home *** CD-ROM | disk | FTP | other *** search
- 'global vars
- Global gDataType As Integer
- Global gDB As Database
- Global gImpDB As Database
- Global gExpDB As Database
- 'Global gstDBName As String
- Global gExpTable As String
-
- 'data types
- Global Const DT_NONE = -1
- Global Const DT_MSACCESS = 0
- Global Const DT_PARADOX = 1
- Global Const DT_FOXPRO25 = 2
- Global Const DT_FOXPRO20 = 3
- Global Const DT_DBASEIV = 4
- Global Const DT_DBASEIII = 5
- Global Const DT_BTRIEVE = 6
- Global Const DT_SQLDB = 7
- Global Const DT_TABDELIM = 8
-
- Function DupeTableName (tname As String) As Integer
- For i = 0 To fTables.cTableList.ListCount - 1
- If UCase(fTables.cTableList.List(i)) = UCase(tname) Then
- DupeTableName = True
- Exit Function
- End If
- Next
- DupeTableName = False
- End Function
-
- Sub Export (tbl As String, todb As String)
-
- On Error GoTo ExpErr
-
- Dim Connect As String, newtbl As String
- Dim errstate As Integer
- Dim idx As Index
- Dim ss As String 'local copy of sql string
- Dim fs As String, fr As String 'field and from string for SQL
-
- If gDataType = DT_SQLDB Then
- Set gExpDB = OpenDatabase("", 0, 0, "odbc;")
- If gExpDB Is Nothing Then Exit Sub
- End If
-
- SetHourglass VDMDI
- MsgBar "Exporting '" & tbl & "'", True
-
- errstate = 1
- Select Case gDataType
- Case DT_MSACCESS
- Connect = "[;database=" & todb & "]."
- Set gExpDB = OpenDatabase(todb)
- Case DT_PARADOX
- Connect = "[Paradox 3.X;database=" & IMEXStripFileName(todb) & "]."
- Set gExpDB = OpenDatabase(todb, 0, 0, "Paradox 3.X")
- Case DT_FOXPRO25
- Connect = "[FoxPro 2.5;database=" & IMEXStripFileName(todb) & "]."
- Set gExpDB = OpenDatabase(todb, 0, 0, "FoxPro 2.5")
- Case DT_FOXPRO20
- Connect = "[FoxPro 2.0;database=" & IMEXStripFileName(todb) & "]."
- Set gExpDB = OpenDatabase(todb, 0, 0, "FoxPro 2.0")
- Case DT_DBASEIV
- Connect = "[dBase IV;database=" & IMEXStripFileName(todb) & "]."
- Set gExpDB = OpenDatabase(todb, 0, 0, "dBase IV")
- Case DT_DBASEIII
- Connect = "[dBase III;database=" & IMEXStripFileName(todb) & "]."
- Set gExpDB = OpenDatabase(todb, 0, 0, "dBase III")
- Case DT_BTRIEVE
- Connect = "[Btrieve;database=" & todb & "]."
- Set gExpDB = OpenDatabase(todb, 0, 0, "Btrieve")
- Case DT_SQLDB
- Connect = "[" & gExpDB.Connect & "]."
- End Select
- If gDataType = DT_MSACCESS Or gDataType = DT_BTRIEVE Or gDataType = DT_SQLDB Then
- ExpName.Label1 = "Export " & tbl & " to:"
- ExpName.Label2 = "in " & todb
- ExpName.cTable = tbl
- ExpName.Show MODAL
- If Len(gExpTable) = 0 Then
- ResetMouse VBIMEX
- MsgBar "", False
- Exit Sub
- Else
- newtbl = gExpTable
- End If
- Else
- newtbl = tbl
- End If
- MsgBar "Exporting '" & newtbl & "'", True
- If Len(tbl) > 0 Then
- gDB.Execute "select * into " & Connect & StripOwner(newtbl) & " from " & StripOwner(tbl)
-
- errstate = 2
- MsgBar "Creating Indexes for '" & newtbl & "'", True
- gExpDB.TableDefs.Refresh
- For i = 0 To gDB.TableDefs(tbl).Indexes.Count - 1
- Set idx = New Index
- idx.Name = gDB.TableDefs(tbl).Indexes(i).Name
- idx.Fields = gDB.TableDefs(tbl).Indexes(i).Fields
- idx.Unique = gDB.TableDefs(tbl).Indexes(i).Unique
- If gDataType <> DT_SQLDB And gstDataType <> "ODBC" Then
- idx.Primary = gDB.TableDefs(tbl).Indexes(i).Primary
- End If
- gExpDB.TableDefs(tbl).Indexes.Append idx
- Next
- ResetMouse VBIMEX
- MsgBar "", False
- MsgBox "Successfully Exported '" & tbl & "'.", 64
- Else
- ss = fSQL.cSQLStatement
- fs = Mid(ss, 8, InStr(8, UCase(ss), "FROM") - 9)
- fr = " " & Mid(ss, InStr(UCase(ss), "FROM"), Len(ss))
- gDB.Execute "select " & fs & " into " & Connect & newtbl & fr
-
- ResetMouse VBIMEX
- MsgBar "", False
- MsgBox "Successfully Exported SQL Statement.", 64
-
- End If
-
-
- Exit Sub
-
- JetErr:
- MsgBox "Error " & x & " code returned!"
- ResetMouse VBIMEX
- MsgBar "", False
- Exit Sub
-
- ExpErr:
- If Err = 3010 Then 'table exists
- If MsgBox("'" & tbl & "' already exists - overwrite?", 32 + 1 + 256) = 1 Then
- gExpDB.TableDefs.Delete tbl
- Resume
- Else
- ResetMouse VBIMEX
- MsgBar "", False
- Exit Sub
- End If
- End If
-
- 'nuke the new table if the indexes couldn't be created
- If errstate = 2 Then
- gExpDB.TableDefs.Delete tbl
- End If
- ResetMouse VBIMEX
- ShowError
- MsgBar "", False
- Exit Sub
-
- End Sub
-
- Sub ExportTabDelim (tbl As String, todb As String)
- Dim ds As Dynaset
- Dim l As Long
- Dim i As Integer
- Dim st As String
-
- On Error GoTo ExportErr
-
- SetHourglass VBIMEX
- MsgBar "Exporting Data to " & todb, True
-
- If Len(tbl) > 0 Then
- Set ds = gCurrentDB.CreateDynaset(tbl)
- Else
- Set ds = gCurrentDB.CreateDynaset(fSQL.cSQLStatement)
- End If
-
- Open todb For Output As #1
-
- 'output the field names
- st = Chr$(9)
- For i = 0 To ds.Fields.Count - 1
- st = st + ds(i).Name + Chr$(9)
- Next
- Print #1, st
-
- 'output the field contents
- l = 1
- While ds.EOF = False
- st = CStr(l) + Chr$(9)
- For i = 0 To ds.Fields.Count - 1
- st = st + vFieldVal((ds(i))) + Chr$(9)
- Next
- Print #1, st
- ds.MoveNext
- l = l + 1
- Wend
-
- GoTo ExportEnd
-
- ExportErr:
- ShowError
- Resume ExportEnd
-
- ExportEnd:
- Close #1
- ResetMouse VBIMEX
- MsgBar NULL_STR, False
-
- End Sub
-
- Sub IMEXRefreshTables ()
-
- VBIMEX.cTables.Clear
- For i = 0 To gDB.TableDefs.Count - 1
- If (gDB.TableDefs(i).Attributes And DB_SYSTEMOBJECT) = 0 Then
- VBIMEX.cTables.AddItem gDB.TableDefs(i).Name
- End If
- Next
- VBIMEX.cTables.ListIndex = 0
-
- End Sub
-
- Function IMEXStripFileName (fname As String) As String
- On Error Resume Next
- Dim i As Integer
-
- For i = Len(fname) To 1 Step -1
- If Mid(fname, i, 1) = "\" Then
- Exit For
- End If
- Next
-
- IMEXStripFileName = Mid(fname, 1, i - 1)
-
- End Function
-
- Sub Import (tbl As String)
- On Error GoTo ImpErr
-
- Dim oldtbl As String, newtbl As String, Connect As String
- Dim idx As Index
- Dim errstate As Integer
-
- oldtbl = MakeTableName(tbl, False)
- newtbl = MakeTableName(tbl, True)
-
- SetHourglass VDMDI
- MsgBar "Importing '" & newtbl & "'", True
-
- errstate = 1
- Select Case gDataType
- Case DT_MSACCESS
- Connect = "[;database=" & gImpDB.Name & "]."
- Case DT_PARADOX
- Connect = "[Paradox 3.X;database=" & IMEXStripFileName(tbl) & "]."
- Set gImpDB = OpenDatabase(IMEXStripFileName(tbl), 0, 0, "Paradox 3.X")
- Case DT_FOXPRO25
- Connect = "[FoxPro 2.5;database=" & IMEXStripFileName(tbl) & "]."
- Set gImpDB = OpenDatabase(IMEXStripFileName(tbl), 0, 0, "FoxPro 2.5")
- Case DT_FOXPRO20
- Connect = "[FoxPro 2.0;database=" & IMEXStripFileName(tbl) & "]."
- Set gImpDB = OpenDatabase(IMEXStripFileName(tbl), 0, 0, "FoxPro 2.0")
- Case DT_DBASEIV
- Connect = "[dBase IV;database=" & IMEXStripFileName(tbl) & "]."
- Set gImpDB = OpenDatabase(IMEXStripFileName(tbl), 0, 0, "dBase IV")
- Case DT_DBASEIII
- Connect = "[dBase III;database=" & IMEXStripFileName(tbl) & "]."
- Set gImpDB = OpenDatabase(IMEXStripFileName(tbl), 0, 0, "dBase III")
- Case DT_BTRIEVE
- Connect = "[Btrieve;database=" & gImpDB.Name & "]."
- Case DT_SQLDB
- Connect = "[" & gImpDB.Connect & "]."
- End Select
- gDB.Execute "select * into " & newtbl & " from " & Connect & oldtbl
-
- errstate = 2
- MsgBar "Creating Indexes for '" & newtbl & "'", True
- gDB.TableDefs.Refresh
- For i = 0 To gImpDB.TableDefs(oldtbl).Indexes.Count - 1
- Set idx = New Index
- idx.Name = gImpDB.TableDefs(oldtbl).Indexes(i).Name
- idx.Fields = gImpDB.TableDefs(oldtbl).Indexes(i).Fields
- idx.Unique = gImpDB.TableDefs(oldtbl).Indexes(i).Unique
- If gDataType <> DT_SQLDB Then
- idx.Primary = gImpDB.TableDefs(oldtbl).Indexes(i).Primary
- End If
- gDB.TableDefs(newtbl).Indexes.Append idx
- Next
-
- VBIMEX.cTables.AddItem newtbl
- fTables.cTableList.AddItem newtbl
- ResetMouse VBIMEX
- MsgBar "", False
- MsgBox "Successfully Imported '" & newtbl & "'.", 64
-
- Exit Sub
-
- ImpErr:
- 'nuke the new table if the indexes couldn't be created
- If errstate = 2 Then
- gDB.TableDefs.Delete newtbl
- End If
- ResetMouse VBIMEX
- ShowError
- MsgBar "", False
- Exit Sub
-
- End Sub
-
- Function MakeTableName (fname As String, newname As Integer) As String
- On Error Resume Next
- Dim i As Integer, t As Integer
- Dim tmp As String
-
- If gDataType = DT_SQLDB And newname Then
- i = InStr(1, fname, ".")
- If i > 0 Then
- tmp = Mid(fname, 1, i - 1) & "_" & Mid(fname, i + 1, Len(fname))
- End If
- ElseIf InStr(fname, "\") > 0 Then
- 'strip off path
- For i = Len(fname) To 1 Step -1
- If Mid(fname, i, 1) = "\" Then
- Exit For
- End If
- Next
- tmp = Mid(fname, i + 1, Len(fname))
- i = InStr(1, tmp, ".")
- If i > 0 Then
- tmp = Mid(tmp, 1, i - 1)
- End If
- Else
- tmp = fname
- End If
-
- If newname Then
- If DupeTableName(tmp) Then
- t = 1
- While DupeTableName(tmp + CStr(t))
- t = t + 1
- Wend
- tmp = tmp + CStr(t)
- End If
- End If
-
- MakeTableName = tmp
-
- End Function
-
-